import React from 'react';
import axios from 'axios';
import { withRouter } from 'react-router-dom';

@withRouter
//测试路由
class AuthRoute extends React.Component {
    componentDidMount() {
        //已在登录或者注册页面时不需做其他处理
        const publicList = ['/login', '/register'];
        const pathname = this.props.location.pathname;
        if(publicList.indexOf(pathname)>-1) {
            return null;
        }
        //获取用户信息
        //访问权限资源页面时验证权限，如果返回通过则跳转，否则跳到登录页面
        axios.get('/user/info').then(
            res => {
                if(res.status===200) {
                    if(res.data.code === 0) {

                    } else {
                        //console.log(this.props.history);
                        this.props.history.push('/login');
                    }
                    console.log(res.data);
                }
            }
        )
    }

    render() {
        return null
    }
}

export default AuthRoute;